package com.nuumoblie.bluetoothtools.ble.db.model;

/*
 * Copyright (C) 2017 Google Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import android.app.Application;
import android.util.Log;

import androidx.lifecycle.AndroidViewModel;
import androidx.lifecycle.LiveData;

import com.nuumoblie.bluetoothtools.ble.db.AdvertiseDatabase;
import com.nuumoblie.bluetoothtools.ble.db.dao.OnLoadComplete;
import com.nuumoblie.bluetoothtools.ble.db.entity.BleProductTypeEntity;
import com.nuumoblie.bluetoothtools.ble.db.repository.AdvertiseConfigRepository;

import java.util.List;

/**
 * View Model to keep a reference to the word repository and
 * an up-to-date list of all words.
 */

public class ProductTypeViewModel extends AndroidViewModel {

    private AdvertiseConfigRepository mRepository;
    // Using LiveData and caching what getAlphabetizedWords returns has several benefits:
    // - We can put an observer on the data (instead of polling for changes) and only update the
    //   the UI when the data actually changes.
    // - Repository is completely separated from the UI through the ViewModel.
    private LiveData<List<BleProductTypeEntity>> mAllProducts;

    public ProductTypeViewModel(Application application) {
        super(application);
        mRepository = new AdvertiseConfigRepository(application);
        mAllProducts = mRepository.getAllProducts();
    }

    public LiveData<List<BleProductTypeEntity>> getAllProducts() {
        Log.v("lmjssjj","getAllProducts"+mAllProducts+" ");
        return mAllProducts;
    }

    public void getAdvertiseInfo(OnLoadComplete onLoadComplete){
        mRepository.getAdvertiseInfos(onLoadComplete);
    }

    public void insert(BleProductTypeEntity entity) {
        mRepository.insert(entity);
    }
}